<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="${ctx}/resources/semanticui/semantic.min.css"
	rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/swiper-3.4.2.min.css" rel="stylesheet" type="text/css" />
<title>职位详细信息</title>
<style>
.swiper-container {
    width: 100%;
    height: auto;
}   

</style>
</head>
<body>
<input type="hidden" name="jobId" id="jobId" value="${job.id}" />
 
	<div class="ui segment" id="n-page">
		<h3 class="ui header">${job.name}</h3>
		<div>
			所在城市：
			<c:forEach items="${cities}" var="city">
				<c:choose>
					<c:when test="${job.cityId == city.id }">
	            ${city.name}
	        </c:when>
				</c:choose>
			</c:forEach>
			<%-- <br> 职位编号： ${job.jobCode} --%><br> 职位状态：
			<c:choose>
				<c:when test="${job.status > 0 }">
					<font color='green'>正常</font>
				</c:when>
				<c:otherwise>
					<font color='red'>HOLD</font>
				</c:otherwise>
			</c:choose>
			<br> 负责区域： ${job.location}<br> 下属人数： ${job.employeeNum}<br>
			主要职责： ${job.majorDuty}<br> 职位描述： ${job.description}<br>
			期望公司来源1：
			<c:forEach items="${companies}" var="company">
				<c:choose>
					<c:when test="${job.expectcompanyid == company.id }">
	            ${company.name}
	        </c:when>
				</c:choose>
			</c:forEach>
			<br> 期望公司来源2：
			<c:forEach items="${companies}" var="company">
				<c:choose>
					<c:when test="${job.expectcompanyid2 == company.id }">
	            ${company.name}
	        </c:when>
				</c:choose>
			</c:forEach>
			<br> 期望公司来源3：
			<c:forEach items="${companies}" var="company">
				<c:choose>
					<c:when test="${job.expectcompanyid3 == company.id }">
	            ${company.name}
	        </c:when>
				</c:choose>
			</c:forEach>
			<br> 职位有效期： ${job.expiredDateStr}<br> 备注： ${job.comment}<br>
			发布平台：
			<c:choose>
				<c:when test="${job.platformID == 1 }">
		             推荐平台
		    </c:when>
					<c:when test="${job.platformID == 2 }">
		             猎头平台
		    </c:when>
					<c:when test="${job.platformID == 3 }">
		            推荐平台 | 猎头平台
		    </c:when>
					<c:otherwise>
		            无
		    </c:otherwise>
				</c:choose>
				<br> 推荐奖金： ${job.reward}<br> &nbsp;<br>
		</div>
		<h3 class="ui attached header" id="list-title">候选人列表</h3>
		<c:choose>
			<c:when test="${recommends == null or fn:length(recommends)==0 }">
        &nbsp;<br>该职位还没有任何候选人&nbsp;<br>&nbsp;<br>
			</c:when>
			<c:otherwise>
				<div class="ui attached segment" id="list-items">
					<c:forEach items="${recommends}" var="rd">
						<div class="ui segment listitem2 position"
							data-position-id="${rd.id}">
							${rd.name} ${rd.companyname} ${rd.positionname}<br> 面试结果：
							<c:choose>
								<c:when test="${rd.status == 0 }">
                    等待邀请
                </c:when>
								<c:when test="${rd.status == 1 }">
                    推荐中
                </c:when>
								<c:when test="${rd.status == 2 }">
                    推荐成功
                </c:when>
								<c:otherwise>
                    推荐失败
                </c:otherwise>
							</c:choose>
							<br>
						</div>
					</c:forEach>
				</div>
				<br>&nbsp;&nbsp;<br>

				<div class="ui segment" id="btn-next2">
					<div class="fluid ui button" id="next">更多候选人</div>
				</div>
			</c:otherwise>
		</c:choose>
		<h3 class="ui attached header" id="list-title">更多系统匹配候选人</h3>
			
				<div class="swiper-container">
		        <div class="swiper-wrapper">
		        <c:forEach items="${emps}" var="emp" >                	
		       		<div class="swiper-slide">
			       		<c:forEach items="${emp}" var="item">
			        		<div class="s_item">
			        			<div class="ui segment listitem2 position2"
										data-position-id="${item.id}">
										<input type="hidden" id="roleId" name="roleId" value="${item.roleId}">
										${item.name} &nbsp;&nbsp;&nbsp;&nbsp; ${item.companyName}&nbsp;&nbsp;&nbsp;&nbsp;${item.roleName} <br/>
								</div>
			        		</div>
			       		</c:forEach>        		
		       		</div>        	
		        </c:forEach>
		        </div>   
		      	</div>
		      	<c:if test="${empslength>0}">
		      		<div class="swiper-pagination" style="padding-left:50%;"></div>
				</c:if>
      	</div>
		<br>&nbsp;&nbsp;<br>
		<div class="ui center aligned segment" id="choice-buttons">
			<div class="two ui buttons" style="width:90%;">
				<div class="ui button active dog" id="editjob">编辑职位</div>
				<div class="ui button dog" id="holdjob">Hold职位</div>
			</div>
		</div>

	</div>

	<!-- 测试用，正式发布关闭 -->
	<!--
<div id="testid">
点击获取更多数据
</div>
-->

	<input type="hidden" name="lastperson" id="lastperson"
		value="${fn:length(recommends)}" />
	<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes" />

	<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
	<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
	<script src="${ctx}/resources/swiper-3.4.2.jquery.min.js"></script>
	<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'showOptionMenu']  
});

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'next') {
                //datasource.moredata();
              //location.href = '${ctx}/wechat/hunter/hr/toViewRecommend.page?positionid='+${job.id};
              location.href = '${ctx}/wechat/hunter/toViewRecommend.do?positionid='+${job.id};
            }
            if($(this).attr('id') == 'more2') {
            location.href = '${ctx}/wechat/hunter/toViewJob.page?positionid='+${job.id};
          }
            if($(this).attr('id') == 'editjob') {
                location.href = '${ctx}/wechat/hunter/toEditJob.page?positionid='+${job.id};
            }
            if($(this).attr('id') == 'holdjob') {
                var urlHold = '${ctx}/wechat/hunter/holdJobDesc.do?jobid='+${job.id};
                $.ajax({ 
                    url: urlHold, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            alert("成功更改职位状态");
                            location.href = '${ctx}/wechat/hunter/joblist.page';
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
                });
            }
        } 
    };

    var datasource_del = { 
        moredata: function() { 
            var getUrl = '${ctx}/wechat/hunter/moreJobRecommend.do?jobid='+${job.id};
            var offset  = $('#lastperson').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "&offset=" + offset;

            if(hasmore != "yes"){
                alert("已经没有更多数据了");
                return false;
            }
            var that = this;

            $.ajax({ 
                    url: getUrl, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            that.appenddata(data);
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
            });
        },

        appenddata:function(data) { 
            var offset = parseInt($('#lastperson').val());
            var divstring = "";
            var recommends = data.recommends;

            var count = recommends.length;
            offset += parseInt(count);
            $('#lastperson').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
            }

            for (var i in recommends) {
                var rd = recommends[i];

                divstring += '<div class="ui segment listitem2 position" data-position-id="'+ rd.id +'">';
                divstring += rd.name;
                divstring += ' ';
                divstring += rd.companyname;
                divstring += ' ';
                divstring += rd.positionname;
                divstring += '<br>';
                if(rd.status == 0) {
                    divstring += '推荐中';
                } else if(rd.status == 1) {
                    divstring += '推荐成功';
                } else {
                    divstring += '推荐失败';
                }
                divstring += '</div>';
            }

            var newdata = $(divstring);
            $('#list-items').append(newdata);
        }
    };

    $(document).ready(function() { 
            $('.button').on('click', handler.activate);
          /*   $('.dropdown').dropdown({
                fullTextSearch:false,
            }); */

            $('.position').on('click', function() {
                var recommendid = $(this).attr('data-position-id');
                var getUrl = '${ctx}/wechat/hunter/toInterview.do?recommendid='+recommendid;
                location.href = getUrl;
            });
            $('.position2').on('click', function() {
              var empid = $(this).attr('data-position-id');
              var getUrl = '${ctx}/wechat/hunter/toViewCandidateDetail.do?jobid='+${job.id}+'&empid='+empid;
              location.href = getUrl;
          });
        
            $('#testid').on('click', function(){
                datasource.moredata();
            });
            wx.ready(function() {
<c:choose>
    <c:when test="${job.platformID == 2 }">
            wx.onMenuShareAppMessage({
                title: 'Headoffer--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });
    </c:when>
    <c:otherwise>
            wx.onMenuShareAppMessage({
                title: '跳哪里--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: '跳哪里--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg'
            });
    </c:otherwise>
</c:choose>


            wx.showOptionMenu();

        });

    });

</script>
<script>   
window.onload = function() {
  var mySwiper = new Swiper ('.swiper-container', {
	mode: 'horizontal',
    loop: false,
    // 如果需要分页器
    initialSlide :0,
    pagination: '.swiper-pagination',
    paginationClickable :true,
    slidesPerView:'auto',
    observer:true,//修改swiper自己或子元素时，自动初始化swiper 
    observeParents:true,//修改swiper的父元素时，自动初始化swiper 
    spaceBetween: 30,
    onSlideChangeEnd: function(swiper){ 
        swiper.update(); //swiper更新
    } 
  });   
}
  </script>
  
</body>
</html>